package com.jackyzgy.test.Jdom;

import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

public class MainTest1 {

	public static void main(String[] args) throws DocumentException {
		StringBuffer sb = new StringBuffer("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:com=\"http://www.chinamobile.com/vgop/serviceorder/v1_0/common\" xmlns:v1=\"http://www.chinamobile.com/vgop/serviceorder/v1_0\">");
		sb.append("<soapenv:Header>");
		sb.append("<com:timeStamp>20120627000940</com:timeStamp>");
		sb.append("<com:originalAddress>");
		sb.append("<com:platType>104000</com:platType>");
		sb.append("<com:provType>591</com:provType>");
		sb.append("</com:originalAddress>");
		sb.append("<com:destAddress>");
		sb.append("<com:platType>229017</com:platType>");
		sb.append("<com:provType>591</com:provType>");
		sb.append("</com:destAddress>");
		sb.append("<com:sendAddress>");
		sb.append("<com:platType>100000</com:platType>");
		sb.append("<com:provType>591</com:provType>");
		sb.append("</com:sendAddress>");
		sb.append("<com:version>1.0.0</com:version>");
		sb.append("<com:transactionID>20120627000918648721</com:transactionID>");
		sb.append("<com:msgName>syncOrderRelationReq</com:msgName>");
		sb.append("</soapenv:Header>");
		sb.append("<soapenv:Body>");
		sb.append("<v1:syncOrderRelation>");
		sb.append("<v1:syncOrderRelationReq>");
		sb.append("<com:subscriptionInfo>");
		sb.append("<com:oprTime>20120627001136</com:oprTime>");
		sb.append("<com:effTime>20120627001135</com:effTime>");
		sb.append("<com:expireTime>30000101000000</com:expireTime>");
		sb.append("<com:feeUser_ID>13400604374</com:feeUser_ID>");
		sb.append("<com:destUser_ID>13400604374</com:destUser_ID>");
		sb.append("<com:actionID>06</com:actionID>");               
		sb.append("<com:actionReasonID>2</com:actionReasonID>");
		sb.append("<com:servType>229925</com:servType>");
		sb.append("<com:subServType>22992500001</com:subServType>");
		sb.append("<com:SPID>0</com:SPID>");
		sb.append("<com:SPServID>0</com:SPServID>");
		sb.append("<com:accessMode>01</com:accessMode>");
		sb.append("<com:feeType>2</com:feeType>");
		sb.append("</com:subscriptionInfo>");
		sb.append("</v1:syncOrderRelationReq>");
		sb.append("</v1:syncOrderRelation>");
		sb.append("</soapenv:Body>");
		sb.append("</soapenv:Envelope>");
		
		Document document = DocumentHelper.parseText(sb.toString());
		String selectNodes = null;
		
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:timeStamp";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:originalAddress//com:provType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:originalAddress//com:platType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:destAddress//com:provType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:destAddress//com:platType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:sendAddress//com:provType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:sendAddress//com:platType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:version";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:transactionID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Header//com:msgName";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:oprTime";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:effTime";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:expireTime";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:feeUser_ID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:destUser_ID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:actionID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:actionReasonID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:servType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:subServType";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:SPID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:SPServID";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:accessMode";
		System.out.println(dealXml(document,selectNodes));
		selectNodes = "//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo//com:feeType";
		System.out.println(dealXml(document,selectNodes));
		
		
		
//		try {
//			Document document = DocumentHelper.parseText(sb.toString());
//			List<Element> list = document.selectNodes("//soapenv:Envelope//soapenv:Header");
//			List<Element> sublist = new ArrayList<Element>();
//			
//			if(list != null && list.size() > 0){
//				for (Element item : list) {
//					System.out.println(item.elementTextTrim("com:msgName"));
//					System.out.println(item.elementTextTrim("com:transactionID"));
//					System.out.println(item.elementTextTrim("com:version"));
//					
//					sublist = item.selectNodes("//com:sendAddress");
//					if(sublist != null && sublist.size() > 0){
//						for (Element subitem : sublist) {
//							System.out.println(subitem.elementTextTrim("com:provType"));
//							System.out.println(subitem.elementTextTrim("com:platType"));
//						}
//					}
//					
//					sublist = item.selectNodes("//com:destAddress");
//					if(sublist != null && sublist.size() > 0){
//						for (Element subitem : sublist) {
//							System.out.println(subitem.elementTextTrim("com:provType"));
//							System.out.println(subitem.elementTextTrim("com:platType"));
//						}
//					}
//					
//					sublist = item.selectNodes("//com:originalAddress");
//					if(sublist != null && sublist.size() > 0){
//						for (Element subitem : sublist) {
//							System.out.println(subitem.elementTextTrim("com:provType"));
//							System.out.println(subitem.elementTextTrim("com:platType"));
//						}
//					}
//					
//					System.out.println(item.elementTextTrim("com:timeStamp"));
//				}
//			}
//			
//			list = document.selectNodes("//soapenv:Envelope//soapenv:Body//v1:syncOrderRelation//v1:syncOrderRelationReq//com:subscriptionInfo");
//			sublist = new ArrayList<Element>();
//			
//			if(list != null && list.size() > 0){
//				for (Element item : list) {
//					System.out.println(item.elementTextTrim("com:oprTime"));
//					System.out.println(item.elementTextTrim("com:effTime"));
//					System.out.println(item.elementTextTrim("com:expireTime"));
//					System.out.println(item.elementTextTrim("com:feeUser_ID"));
//					System.out.println(item.elementTextTrim("com:destUser_ID"));
//					System.out.println(item.elementTextTrim("com:actionID"));
//					System.out.println(item.elementTextTrim("com:actionReasonID"));
//					System.out.println(item.elementTextTrim("com:servType"));
//					System.out.println(item.elementTextTrim("com:subServType"));
//					System.out.println(item.elementTextTrim("com:SPID"));
//					System.out.println(item.elementTextTrim("com:SPServID"));
//					System.out.println(item.elementTextTrim("com:accessMode"));
//					System.out.println(item.elementTextTrim("com:feeType"));
//				}
//			}
//		} catch (DocumentException e) {
//			e.printStackTrace();
//		}
	}
	
	private static String dealXml(Document document,String selectNodes){
		String returnCode = null;
		
		List<Element> list = document.selectNodes(selectNodes);
		
		if(list != null && list.size() > 0){
			for (Element item : list) {
				returnCode = item.getText();
			}
		}
		return returnCode;
	}
}
